#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:__init__.py.py
# author:jackiex
# datetime:2022/2/7 12:50
# software: PyCharm

'''
    this is function  description 
'''

from flask_limiter import Limiter, ExemptionScope
from flask_limiter.util import get_remote_address


limiter = None


def init_limiter(app):
    global limiter
    limiter = Limiter(
        app=app,
        key_func=get_remote_address,
        default_limits=app.config.get('DEFAULT_LIMITS').split(',')
    )


def init_router(app):
    # version test
    from .apiVersionResource import apiversion_blueprint
    app.register_blueprint(apiversion_blueprint, url_prefix="/api_1_0")

    # insecurestudent blueprint register
    from .insecurestudentResource import insecure_student_blueprint
    app.register_blueprint(insecure_student_blueprint, url_prefix="/api_1_0")

    # insecurecourse blueprint register
    from .insecurecourseResource import insecure_course_blueprint
    app.register_blueprint(insecure_course_blueprint, url_prefix="/api_1_0")

    # ssoUser blueprint register
    from .ssoUserResource import ssouser_blueprint
    app.register_blueprint(ssouser_blueprint, url_prefix="/api_1_0")

    # insecure_ssoUser blueprint register
    from .insecuressoUserResource import insecure_ssouser_blueprint
    app.register_blueprint(insecure_ssouser_blueprint, url_prefix="/api_1_0")

    # 在蓝图注册部分声明limiter对insecure_course接口的豁免
    limiter.exempt(
        insecure_course_blueprint,
        flags=ExemptionScope.DEFAULT | ExemptionScope.APPLICATION | ExemptionScope.ANCESTORS
    )